<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">

    <link rel="stylesheet" href="bootstrap-3.3.4/dist/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="Flat-UI-master/dist/css/flat-ui.min.css"/>
    <script src="bootstrap-3.3.4/dist/js/jquery-3.5.1.min.js"></script>
    <script src="bootstrap-3.3.4/dist/js/jquery.cookie-1.4.1.min.js"></script>
    <script src="bootstrap-3.3.4/dist/js/bootstrap.min.js"></script>
    <script src="Flat-UI-master/dist/js/flat-ui.min.js"></script>
    <script src="custom/util.js"></script>

    <title>主页</title>

    <style>
        .row {
            margin-top: 20px;
        }

        .center {
            text-align: center;
        }

        .pagination {
            background: #cccccc;
        }
    </style>
</head>

<body>
<script>
    $(function () {
        // 允许跨域传cookie
        $.ajaxSetup({crossDomain: true, xhrFields: {withCredentials: true}});

        // 请求拿到所有 未接单 的订单
        $.ajax({
            url: url + "/order/all",
            success: function (res) {
                if(res.flag === 5000) {
                    alert(res.data);
                    return;
                }
                for (var order of res.data) {
                    var node = document.createElement("div");
                    node.setAttribute("class", "col-sm-4 col-md-3");

                    var node2 = document.createElement("div");
                    node2.setAttribute("class", "thumbnail");


                    // 订单描述
                    var desc = document.createElement("div");
                    desc.setAttribute("class", "alert alert-warning");
                    desc.setAttribute("role", "alert");
                    desc.setAttribute("style", "height:62.55px; overflow-y: auto;");
                    desc.innerText = order.description;
                    node2.append(desc);

                    var others = document.createElement("div");
                    others.setAttribute("class", "caption center");


                    // 订单提交者
                    var sender = document.createElement("p");
                    sender.innerText = "发布者：" + order.senderName;
                    others.append(sender);

                    // 订单价格
                    var price = document.createElement("p");
                    price.innerText = "价格：" + order.price;
                    others.append(price);


                    // 订单配送时间
                    var when = document.createElement("p");
                    when.innerText = "指定收件时间：" + order.when.substring(0, 19).replace("T", " ");
                    others.append(when);

                    // 订单配送地点
                    var location = document.createElement("p");
                    location.innerText = "收件地点：" + order.location
                    location.setAttribute("style", "height:61.09px; overflow-y: auto;");
                    others.append(location);


                    var detail = document.createElement("a");
                    detail.setAttribute("class", "btn btn-primary btn-block");
                    detail.setAttribute("role", "button");
                    detail.setAttribute("href", "OrderDetail.html?" + order.id);
                    detail.innerText = "查看详情";
                    others.append(detail);

                    node2.append(others);

                    node.append(node2);
                    $("#all-order").append(node);
                }
            },
            error: function () {
                alert("获取全部订单失败，请联系开发者解决问题")
            }
        })

        // 注销
        $("#logout").click(function () {
            $("#logout").hide();
            $("#register").show();
            $("#login").show();
            $.ajax({
                url: url + "/user/logout",
                success: function (data) {
                    console.log("log out success")
                },
                error: function () {
                    console.log("error");
                }
            });
        });

        // // 查看当前登录状态（不太好，因为浏览器会自带cookie的）
        // if ($.cookie("JSESSIONID") === null) {
        //     $("#register").show();
        //     $("#login").show();
        // } else {
        //     $("#logout").show();
        // }

        // 老的方式，再次使用
        $.ajax({
            url: url + "/user/check",
            success: function (data) {
                if (data["flag"] === 2000) {
                    // 已经登录了
                    // $("#pick").show();
                    $("#logout").show();
                } else {
                    // 还没登录
                    $("#register").show();
                    $("#login").show();
                }
            },
            error: function () {
                console.log("error");
            }
        });
    })
</script>


<!-- Static navbar -->
<div class="navbar navbar-default navbar-static-top" role="navigation">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="sr-only">这什么东西</span>
            </button>
            <a class="navbar-brand" href="Index.html">快递代取系统</a>
        </div>
        <div class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                <li class="active"><a href="Index.html">首页</a></li>
                <li><a href="NewOrder.html">创建订单</a></li>
                <li><a href="Order.html">我的订单</a></li>
                <li><a href="PickedOrder.html">我的接单</a></li>
                <li><a href="UserInfo.html">个人中心</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right hidden-sm">
                <li><a id="login" href="Login.html" style="display: none;">登录</a></li>
                <li><a id="register" href="Register.html" style="display: none">注册</a></li>
                <li><a id="logout" href="#" style="display: none">注销</a></li>

                <li>
                    <a href="Cart.html"><span class="glyphicon glyphicon-shopping-cart">购物车</span></a>
                </li>
            </ul>
        </div>
    </div>
</div>


<!--content-->
<div class="container">

    <div class="jumbotron">
        <h1>快递代取系统</h1>
        <p>...</p>
        <p><a class="btn btn-primary btn-lg" href="#" role="button">了解更多</a></p>
    </div>

    <ul class="nav nav-tabs" id="myTabs">
        <li class="active"><a href="#">默认排序</a></li>
        <li><a href="#">浏览量从高到低</a></li>
        <li><a href="#">浏览量从低到高</a></li>
        <li><a href="#">更新时间从新到老</a></li>
        <li><a href="#">更新时间从老到新</a></li>
        <li><a href="#">价格从小到大</a></li>
        <li><a href="#">价格从大到小</a></li>
    </ul>


    <!-- 订单详情页， 包含了所有用户未接单， 供人选择 -->
    <div id="all-order" class="row">
        <!--        <div class="col-sm-4 col-md-3">-->
        <!--            <div class="thumbnail">-->
        <!--                <a href="OrderDetail.html">-->
        <!--                    <img style="width: 100%; height: 200px; display: block;" alt="100%x200"-->
        <!--                         src=""-->
        <!--                         data-src="holder.js/100%x200" data-holder-rendered="true">-->
        <!--                </a>-->
        <!--                <div class="alert alert-warning" role="alert" style="overflow-y: auto; height: 62.55px;">-->
        <!--                    Better check yourself, you're not looking too good.-->
        <!--                </div>-->

        <!--                <div class="caption center">-->
        <!--                    <p>-->
        <!--                        发布者：tony-->
        <!--                    </p>-->
        <!--                    <p>-->
        <!--                        <span>价格：</span>-->
        <!--                        <span>5</span>-->
        <!--                    </p>-->
        <!--                    <p>-->
        <!--                        <span>时间：</span>-->
        <!--                        <span>2021-2-2</span>-->
        <!--                    </p>-->
        <!--                    <p>-->
        <!--                        <span>地点：</span>-->
        <!--                        <span>第八宿舍</span>-->
        <!--                    </p>-->
        <!--                    <a class="btn btn-primary btn-block" role="button" href="OrderDetail.html">查看详情</a>-->
        <!--                </div>-->
        <!--            </div>-->
        <!--        </div>-->

        <!--        <div class="col-sm-4 col-md-3">-->
        <!--            <div class="thumbnail">-->
        <!--                <a href="OrderDetail.html">-->
        <!--                    <img style="width: 100%; height: 200px; display: block;" alt="100%x200"-->
        <!--                         src=""-->
        <!--                         data-src="holder.js/100%x200" data-holder-rendered="true">-->
        <!--                </a>-->
        <!--                <div class="caption center">-->
        <!--                    <h3>书名</h3>-->
        <!--                    <p><span>价格:</span><span>100.00</span></p>-->
        <!--                    <p><a class="btn btn-primary btn-block" role="button" href="OrderDetail.html">查看详情</a></p>-->
        <!--                </div>-->
        <!--            </div>-->
        <!--        </div>-->

    </div>

    <!-- 分页 -->
    <nav class="center">
        <ul class="pagination  pagination-lg">
            <li>
                <a href="#" aria-label="Previous">
                    <span aria-hidden="true">首页</span>
                </a>
            </li>
            <li><a href="#">1</a></li>
            <li><a href="#">2</a></li>
            <li><a href="#">3</a></li>
            <li><a href="#">4</a></li>
            <li><a href="#">5</a></li>
            <li>
                <a href="#" aria-label="Next">
                    <span aria-hidden="true">末页</span>
                </a>
            </li>
        </ul>
    </nav>

</div>


<!--footer-->
<div class="navbar navbar-default navbar-static-bottom">
    <p style="text-align: center">版权声明区</p>
</div>

</body>
</html>